package com.mz.mattress.admin.api.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mz.mattress.admin.api.req.InvestorQueryReq;
import com.mz.mattress.admin.api.resp.InvestorSum;
import com.mz.mattress.admin.service.InvestorService;
import com.mz.mattress.api.common.Constants;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.Investor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@Slf4j
@RestController
@RequestMapping(Constants.ADMIN_PATH + "investor")
public class InvestorController {

    @Autowired
    private InvestorService investorService;

    @GetMapping(value = "list")
    public Result<List<Investor>> list() {
        return investorService.list();
    }

    @GetMapping("/listPage")
    public Result<IPage<Investor>> listPage(InvestorQueryReq req) {
        return investorService.listPage(req);
    }

    @GetMapping(value = "/{id}")
    public Result<Investor> detail(@PathVariable Integer id) {
        return investorService.getById(id);
    }

    @GetMapping(value = "/headSum")
    public Result<InvestorSum> headSum(@RequestParam Integer id) {
        return investorService.headSum(id);
    }

    @PostMapping
    public Result add(@RequestBody Investor investor) {
        return investorService.add(investor);
    }

    @PutMapping
    public Result update(@RequestBody Investor investor) {
        return investorService.updateById(investor);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Integer> ids) {
        return investorService.deleteByIds(ids);
    }

}
